#pragma once
#include "LMCommon.h"
#include <string>
#include <boost/date_time.hpp>

#define MAX_TRANSACTIONS	(4096)

class LMContext
{
public:
	LMContext(void);
	virtual ~LMContext(void);

	std::string User() const { return _user; }
	void User(std::string val) { _user = val; }
	std::string Password() const { return _password; }
	void Password(std::string val) { _password = val; }
	std::string PoolIp() const { return _poolIp; }
	void PoolIp(std::string val) { _poolIp = val; }
	int PoolPort() const { return _poolPort; }
	void PoolPort(int val) { _poolPort = val; }
	int ThreadNum() const { return _threadNum; }
	void ThreadNum(int val) { _threadNum = val; }
	std::string PasswordSha1();

	void resetMinerStartTime();
	boost::posix_time::ptime minerStartTime();

	uint32 uniqueMerkleSeedGenerator;
	uint32 miningStartTime;

	CRITICAL_SECTION cs_xptClient;

	// stats
	uint32 totalCollisionCount;
	uint32 totalShareCount;
	uint32 totalRejectedShareCount;
	uint32 total2ChainCount;
	uint32 total3ChainCount;
	uint32 total4ChainCount;
	uint32 totalSieveCount;

	uint32 monitorCurrentBlockHeight;
	uint32 monitorCurrentBlockTime;

	// miner version string (for pool statistic)
	std::string minerVersionString;

	struct  
	{
		CRITICAL_SECTION cs_work;
		uint32	algorithm;
		// block data
		uint32	version;
		uint32	height;
		uint32	nBits;
		uint32	timeBias;
		uint8	merkleRootOriginal[32]; // used to identify work
		uint8	prevBlockHash[32];
		uint8	target[32];
		uint8	targetShare[32];
		uint32  targetCompact;
		uint32  shareTargetCompact;
		// extra nonce info
		uint8	coinBase1[1024];
		uint8	coinBase2[1024];
		uint16	coinBase1Size;
		uint16	coinBase2Size;
		// transaction hashes
		uint8	txHash[32*MAX_TRANSACTIONS];
		uint32	txHashCount;
	}workDataSource;

	uint8 algorithmInited[32];

	int workerAccepterPort;
    sint32 developerFeeCount;
private:
	std::string _user;
	std::string _password;
	std::string _poolIp;
	int _poolPort;
	int _threadNum;
	boost::posix_time::ptime _minerStartTime;
};

